//
//  BlogTableViewHelper.m
//  SimpleSrore
//
//  Created by ggx on 2017/3/16.
//  Copyright © 2017年 高广校. All rights reserved.
//

#import "BlogTableViewHelper.h"

#import "UserCenterCell.h"
#import "OnceTitleCell.h"
#import "UserCenterFootCell.h"

#import "BSButtonView.h"
@interface BlogTableViewHelper()<UserCenterFootCellDelegate>

@property (weak, nonatomic) CGTableView_loadView2 *tableView;

@property (nonatomic,strong)NSArray *userArray;
@property (assign, nonatomic) NSUInteger userId;
@property (strong, nonatomic) NSMutableArray *blogs;
//@property (strong, nonatomic) UserAPIManager *apiManager;

@end
@implementation BlogTableViewHelper
+ (instancetype)helperWithTableView:(UITableView *)tableView userId:(NSUInteger)userId {
    return [[BlogTableViewHelper alloc] initWithTableView:tableView userId:userId];
}
- (instancetype)initWithTableView:(UITableView *)tableView userId:(NSUInteger)userId {
    if (self = [super init]) {
        
        self.userId = userId;
        tableView.delegate = self;
        tableView.dataSource = self;
        self.blogs = [NSMutableArray new];
        self.tableView = (CGTableView_loadView2 *)tableView;
        self.tableView.loadDelegate =self;
//        self.tableView
        
        _userArray = @[@"我的店员",@"历史订单",@"消息",@"修改密码",@"意见反馈",@"关于我们",@"清除缓存",@""];
//        __weak typeof(self) weakSelf = self;
//        [tableView registerClass:[BlogCell class] forCellReuseIdentifier:BlogCellReuseIdentifier];
//        tableView.header = [MJRefreshAnimationHeader headerWithRefreshingBlock:^{//下拉刷新
//            [weakSelf.apiManage refreshUserBlogsWithUserId:userId completionHandler:^(NSError *error, id result) {
//                //...略
//            }];
//        }];
//        tableView.footer = [MJRefreshAnimationFooter headerWithRefreshingBlock:^{//上拉加载
//            [weakSelf.apiManage loadMoreUserBlogsWithUserId:userId completionHandler:^(NSError *error, id result) {
//                //...略
//            }];
//        }];
    }
    return self;
}
-(void)refreshView{
    [self.blogs removeAllObjects];
    [self.blogs addObjectsFromArray:@[
  @{@"text":@"便利店名称",@"value":@"平顶山便利店"},
  @{@"text":@"店员名字",@"value":@"张大小姐"},
  @{@"text":@"手机号",@"value":@"1821561351"}]];
}
-(void)loadMore{
    
}
#pragma mark - UITableViewDataSource && Delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return section == 0?self.blogs.count:_userArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        static NSString *cellIdenti = @"UserCenterCell";
            UserCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenti];
            if (!cell) {
                cell = [[UserCenterCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdenti];
            }
            cell.userDic = _blogs[indexPath.row];
            return cell;
    }else{
        //最后一个四股
        if (indexPath.row != _userArray.count - 1) {
            static NSString *cellIdenti = @"OnceTitleCell";
            OnceTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenti];
            if (!cell) {
                cell = [[OnceTitleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdenti];
            }
            cell.data = [NSString stringWithFormat:@"%@",_userArray[indexPath.row]];
            
            return cell;
        }else{
            static NSString *cellIdenti = @"UserCenterFootCell";
            UserCenterFootCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenti];
            if (!cell) {
                cell = [[UserCenterFootCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdenti];
            }
            cell.delegate  = self;
            return cell;
        }
       
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (indexPath.section == 1&&indexPath.row == _userArray.count - 1)?100:40;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section == 0?0:10;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.didSelectRowAtPushViewIndexPath) {
        self.didSelectRowAtPushViewIndexPath(indexPath.row + 3);//
    }
}
#pragma mark - UserCenterFoot delegate
-(void)exitAction:(NSInteger)index{
    [CustomUtil delAcessToken];//删除 token
    if (self.didSelectRowAtPushViewIndexPath) {
        self.didSelectRowAtPushViewIndexPath(100);
    }
}

@end
